﻿//------------------------------------------------------------------------------
// System Name:   Customer Service Platform
// Component:     CIS  Domestic BranchContactsHelper
// Created By:    Samara Jiang (samaraj@wicresoft.com)
// Created Date:  2011-2-10
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using ASBCC.Database.EntityFramework;
using BEGDC.CC.BL.CCFlow;
using BEGDC.Utility.Castle;

namespace ASBCC.Business.CIS
{
    /// <summary>
    /// CIS 国内 分公司通讯录模块数据库访问类
    /// </summary>
    public static class BranchContactsHelper
    {
        /// <summary>
        /// 将一个BranchContacts的激活状态设为未激活
        /// </summary>
        public static void SetBranchContactsDisabled(int directoryID)
        {
            using (var dc = new CCEntities())
            {
                dc.BranchContact.FirstOrDefault(p => p.DirectoryID == directoryID).Disabled = true;
                dc.SaveChanges();
            }
        }

        /// <summary>
        /// 根据当前ID获取Name
        /// </summary>
        public static IEnumerable getName(int entityID)
        {
            using (var dc = new CCEntities())
            {
                var name = dc.BranchContact.FirstOrDefault(p => p.DirectoryID == entityID).Name;
                return name;
            }
        }


        /// <summary>
        /// 分公司通讯录上传功能
        /// </summary>
        public static void BranchContactUpload(ObjectContext dc, BranchContact branchContact, FileUpload file)
        {
            //不需要判断长度为0  if (file != null && file.HasFile && file.PostedFile.ContentLength > 0)
            if (file != null)
            {
                string fileName = System.IO.Path.GetFileName(file.PostedFile.FileName);

                string path = BEGDC.CC.BL.Workflow.Configuration.AttachmentPath + "CISResource\\" + fileName;
                file.PostedFile.SaveAs(path);
                branchContact.FilePath = path;
                branchContact.Exist = true;
            }

        }


        /// <summary>
        /// 根据directoryID获取FilePath
        /// </summary>
        public static IEnumerable GetFilePath(int directoryID)
        {
            using (var dc = new CCEntities())
            {

                var filePath = dc.BranchContact.FirstOrDefault(p => p.DirectoryID == directoryID).FilePath;
                return filePath;
            }
        }

    }
}
